<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>门诊查询--中软高科-2015</title>
<meta charset="UTF-8">


<!-- 超链接和表单提交相当于重定向,重定向加"/"是服务器的根目录,所以最好用相对路径 -->
<!-- 而转发"/"则是代表项目的根目录,且controller里面的return默认是转发, -->
<!-- 视图解析器加前缀和后缀只能加在转发上 -->
<link rel="stylesheet" type="text/css" href="Css/bootstrap.css" />
<link rel="stylesheet" type="text/css"
	href="Css/bootstrap-responsive.css" />
<link rel="stylesheet" type="text/css" href="Css/style.css" />
<script type="text/javascript" src="Js/jquery.js"></script>
<script type="text/javascript" src="Js/jquery.sorted.js"></script>
<script type="text/javascript" src="Js/bootstrap.js"></script>
<script type="text/javascript" src="Js/ckform.js"></script>
<script type="text/javascript" src="Js/common.js"></script>

<style type="text/css">
body {
	padding-bottom: 40px;
}

.sidebar-nav {
	padding: 9px 0;
}

@media ( max-width : 980px) {
	/* Enable use of floated navbar text */
	.navbar-text.pull-right {
		float: none;
		padding-left: 5px;
		padding-right: 5px;
	}
}
</style>
<script type="text/javascript">
	$(function() {
		$('#newNav').click(function() {
			//window.location.href 和没有location.href 区别,做重定向
			// top.location.href(),回到最外层的页面
			//parent.location.herf(),回到上一层的页面
			window.location.href = "getAddBook";
		});
	});

	function checkall() {
		var alls = document.getElementsByName("check");
		var ch = document.getElementById("checkall");
		if (ch.checked) {
			for (var i = 0; i < alls.length; i++) {
				alls[i].checked = true;
			}
		} else {
			for (var i = 0; i < alls.length; i++) {
				alls[i].checked = false;
			}
		}
	}
	function delAll() {
		//得到一个数组
		var alls = document.getElementsByName("check");
		//js声明数组的方式
		var ids = new Array();
		for (var i = 0; i < alls.length; i++) {
			//判断CheckBox的状态,alls[i].checked为true表示被选中
			if (alls[i].checked) {
				//js数组添加元素的的方式ids.push(),给元素赋值的方式是alls[i].value
				var a = alls[i].value;
				ids.push(a);
			}
		}
		if (ids.length > 0) {
			//confirm(确认操作?)是一个弹框,如果点击确定则confirm(确认操作?)的值是true
			if (confirm("确认操作?")) {
				var x = "delBook?codes=";
				for (var i = 0; i < ids.length; i++) {
					//得到的是bookCode
					//用foreach   mybatis的底层实现
					if (i == 0) {
						x += ids[i];
					} else {
						x += "&codes=" + ids[i];
					}

				}
				alert(x);
				location.href = x;
				alert("成功!");
			}
		} else {
			alert("请选中要操作的项");
		}
	}

	function toExcel() {
		//得到一个数组
		var alls = document.getElementsByName("check");
		//js声明数组的方式
		var ids = new Array();
		for (var i = 0; i < alls.length; i++) {
			//判断CheckBox的状态,alls[i].checked为true表示被选中
			if (alls[i].checked) {
				//js数组添加元素的的方式ids.push(),给元素赋值的方式是alls[i].value
				var a = alls[i].value;
				ids.push(a);
			}
		}
		if (ids.length > 0) {
			//confirm(确认操作?)是一个弹框,如果点击确定则confirm(确认操作?)的值是true
			if (confirm("确认操作?")) {
				var x = "ExportToExcel?codes=";
				for (var i = 0; i < ids.length; i++) {
					//得到的是bookCode
					//用foreach   mybatis的底层实现
					if (i == 0) {
						x += ids[i];
					} else {
						x += "&codes=" + ids[i];
					}

				}
				alert(x);
				location.href = x;
				alert("成功!");
			}
		} else {
			alert("请选中要操作的项");
		}
	}
</script>
</head>
<body>

	<form action="bookInfo" method="post" class="definewidth m20">
		<table class="table table-bordered table-hover definewidth m10">
			<tr>
				<td width="10%" class="tableleft">书籍编号：</td>
				<td><input type="text" name="bookCode"
					value="${book.bookCode }" /></td>

				<td width="10%" class="tableleft">书籍名称：</td>
				<td><input type="text" name="bookName"
					value="${book.bookName }" /></td>

				<td width="10%" class="tableleft">书籍作者：</td>
				<td><input type="text" name="bookAuthor"
					value="${book.bookAuthor }" /></td>
			</tr>
			<tr>

				<td width="10%" class="tableleft">书籍价格：</td>

				<td colspan="5"><input type="text" name="bookPrice"
					value="${book.bookPrice }" />&nbsp;至&nbsp;<input type="text"
					name="bookPrice2" value="${book.bookPrice2 }" />
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<button type="submit" class="btn btn-primary">查询</button> <a
					class="btn btn-primary" href="bookInfo?isok=clean">清空</a></td>
			</tr>
		</table>
	</form>

	<table class="table table-bordered table-hover definewidth m10">
		<thead>
			<tr>
				<th><input type="checkbox" id="checkall" onChange="checkall();"></th>
				<th>书籍编号</th>
				<th>书籍名称</th>
				<th>书籍数量</th>
				<th>书籍价格</th>
				<th>书籍作者</th>
				<th>书籍出版商</th>
				<th>操作</th>
			</tr>
		</thead>
		<c:forEach var="b" items="${info }">
			<tr>
				<td style="vertical-align: middle;"><input type="checkbox"
					name="check" value="${b.bookCode }"></td>
				<td style="vertical-align: middle;">${b.bookCode }</td>
				<td style="vertical-align: middle;">${b.bookName }</td>
				<td style="vertical-align: middle;">${b.bookNumber }</td>
				<td style="vertical-align: middle;">${b.bookPrice }</td>
				<td style="vertical-align: middle;">${b.bookAuthor }</td>
				<td style="vertical-align: middle;">${b.bookAddress }</td>
				<td style="vertical-align: middle;"><a href="look.html">详情>>></a>&nbsp;&nbsp;&nbsp;<a
					href="edit.jsp">更改</a>&nbsp;&nbsp;&nbsp;<a href="#">删除</a></td>
			</tr>

		</c:forEach>


	</table>

	<table class="table table-bordered table-hover definewidth m10">
		<tr>
			<th colspan="5">
				<div class="inline pull-right page">
					<a href='bookInfo?nowPage=1'>第一页</a>
					<c:if test="${pb.nowPage>1}">
						<a href='bookInfo?nowPage=${pb.nowPage-1}'>上一页</a>
					</c:if>
					<c:if test="${pb.nowPage==1}">
						<a href='bookInfo?nowPage=1'>上一页</a>
					</c:if>
					<c:if test="${pb.nowPage==pb.totalPage}">
						<a href='bookInfo?nowPage=${pb.totalPage }'>下一页</a>
					</c:if>
					<c:if test="${pb.nowPage<pb.totalPage}">
						<a href='bookInfo?nowPage=${pb.nowPage+1 }'>下一页</a>
					</c:if>
					<a href='bookInfo?nowPage=${pb.totalPage}'>最后一页</a>
					&nbsp;&nbsp;&nbsp; 共<span class='current'>${pb.count }</span>条记录 <span
						class='current'> ${pb.nowPage}/${pb.totalPage} </span>页
				</div>
				<div>
					<button type="button" class="btn btn-success" id="newNav">添加书籍</button>
					&nbsp;&nbsp;&nbsp;
					<button type="button" class="btn btn-success" id="delPro"
						onClick="delAll();">删除</button>
					&nbsp;&nbsp;&nbsp;
					<button type="button" class="btn btn-success" id="delPro"
						onClick="toExcel()";>导出Excel</button>
				</div>
			</th>
		</tr>
	</table>

</body>
<script type="text/javascript">
	
</script>
</html>
